<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>订单管理</title>
    <th:block th:include="base::header"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form method="post" class="layui-form" lay-filter="form">
            <div class="layui-form-item" style="display: none">
                <div class="layui-inline x-body layui-form">
                    <input type="text" id="customId" name="customId" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" >
                <label for="customerName" class="layui-form-label">客户名称
                </label>
                <div class="layui-inline x-body layui-form">
                    <input type="text" id="customerName" name="customName" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" >
                <label for="fullName" class="layui-form-label">客户全称
                </label>
                <div class="layui-inline x-body layui-form">
                    <input type="text" id="fullName" name="fullName" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" >
                <label for="address" class="layui-form-label">地址
                </label>
                <div class="layui-inline x-body layui-form">
                    <input type="text" id="address" name="address" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" >
                <label for="fax" class="layui-form-label">传真
                </label>
                <div class="layui-inline x-body layui-form">
                    <input type="number" id="fax" name="fax" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" >
                <label for="email" class="layui-form-label">邮箱
                </label>
                <div class="layui-inline x-body layui-form">
                    <input type="text" name="email" id="email" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" >
                <label for="ownerName" class="layui-form-label">经理姓名
                </label>
                <div class="layui-inline x-body layui-form">
                    <input type="text" id="ownerName" name="ownerName" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" >
                <label for="ownerTel" class="layui-form-label">联系电话
                </label>
                <div class="layui-inline x-body layui-form">
                    <input type="number" name="ownerTel" id="ownerTel" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" >
                <label for="status" class="layui-form-label">客户状态
                </label>
                <div class="layui-inline x-body layui-form">
                    <select name="status" id="status">
                        <option value='1'>有效客户</option>
                        <option value='2'>无效客户</option>
                    </select>
                </div>
            </div>

            <div class="layui-form-item" >
                <label for="requirement" class="layui-form-label">备注
                </label>
                <div class="layui-inline">
                    <textarea id="requirement" name="note" lay-verify="requirement" style="display: none;"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label  class="layui-form-label"></label>
                <button class="layui-btn" lay-submit lay-filter="add">提交</button>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    var basePath ='[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]';
    var customId=[[${id}]]
    layui.use(
        ['form', 'layer','jquery','layedit','util','laydate'],
        function() {
            $ = layui.jquery;
            var form = layui.form;
            var layer = layui.layer;
            var layedit=layui.layedit;
            var util = layui.util;
            var laydate=layui.laydate;

            $.get(basePath+"/customer/loadedit",{"id":customId},function(res){
                var customer=res.data;
                console.log(customer);
                form.val("form", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                    "customId": customer.customId,
                    "customName": customer.customName,
                    "fullName": customer.fullName,
                    "address": customer.address,
                    "fax": customer.fax,
                    "email": customer.email,
                    "ownerName": customer.ownerName,
                    "ownerTel": customer.ownerTel,
                    "status": customer.status,
                    "note": customer.note
                });
                var index=layedit.build('requirement',{
                    height: 400,
                    uploadImage: {url: 'img', type: 'post'}
                });//编辑器

                form.verify({
                    requirement: function (value) {
                        layedit.sync(index);
                    }
                });
            });

            //监听提交
            form.on('submit(add)',function(data) {
                /*var time=util.toDateString(new Date().getTime(), "yyyy-MM-dd HH:mm:ss");
                data.field.addTime=time;
                data.field.reviseTime=time;*/
                var time=new Date();

                console.log(data.field);
                //发异步，把数据提交给php
                $.post("edit",data.field,function(res){
                    if(res.code==200){
                        layer.alert("编辑成功",{
                            icon:1,
                        },function(){
                            //关闭当前frame
                            xadmin.close();
                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        });
                    }
                });
                //发异步，把数据提交给php
                return false;
            });
        });

</script>
</body>
</html>
